#!/usr/bin/env bash

#更新版本号
gsed -i -r 's/(.*)(testVersionCheck=)([0-9]+)(.*)/echo "\1\2$((\3+1))\4"/ge' src/LoadingUI.ts

#build
egret quickbuild
if [ $? -ne 0 ]; then
    exit
fi

find=$(osascript -e \
'tell application "Google Chrome"
set i to 0
repeat with t in (tabs of (first window ))
    set i to i + 1
    if title of t contains "消灭" then
        set (active tab index of (first window )) to i
        activate
        tell t to reload
        return "ok"
    end if
end repeat
end tell
')

[ "$find" == "ok" ] && exit 0

echo "open new tab"
open http://localhost:3000/launcher/index.html
